#include "application.h"
#include "log/log.h"
#include "common/configmanager/configmanager.h"

#include <iostream>
CApplication::CApplication(/* args */){

}
CApplication::~CApplication(){

}

bool CApplication::init() {

    std::string level, path;
    int64_t     size;
    int         count;
    //配置管理模块初始化
    std::shared_ptr<CConfigManager> pCfgManger = CConfigManager::GetInstance();
    if(pCfgManger!= nullptr){
        std::string stdPath = "E:\\wlr\\cfg\\json.cfg";
        std::cout << "stdPath: " << stdPath << std::endl;
        Json::Value tmpValue = Json::Value::null;
        if(!pCfgManger->loadConfig(stdPath, tmpValue)){
            return false;
        }
        std::cout <<"=================2222222" <<std::endl;
        if (tmpValue.isMember("level") && tmpValue["level"].isString()){
            level = tmpValue["level"].asString().c_str();
        }
        if (tmpValue.isMember("path") && tmpValue["path"].isString()){
            path = tmpValue["path"].asString().c_str();
        }
        if (tmpValue.isMember("size") && tmpValue["size"].isInt64()){
            size = tmpValue["size"].asInt64() * 1024*1024*1024;
        }
        if (tmpValue.isMember("count") && tmpValue["count"].isInt64()){
            count = tmpValue["count"].asInt64();
        }
    }
//   //日志模块初始化
    LogConfig conf2 = {
        .level = level,
        .path  = path,
        .size  = size,
        .count = count,
    };
    INITLOG(conf2);
    return true;
}
